import {defineStore} from "pinia";
import {ref} from "vue";
import {getUserInfo} from "@/api/admin/user.js";
import {removeToken} from "@/composables/cookie.js";

export const userUserStore = defineStore('user',()=>{
    // 用户信息初始化
    const userInfo = ref({})
    //设置用户信息
    function setUserInfo(){
        getUserInfo().then((res)=>{
            if(res.success === true){
                userInfo.value = res.data
            }
        })
    }

    //退出登录
    function logout(){
        //删除token令牌
        removeToken()
        userInfo.value={}
    }

    return {userInfo,setUserInfo,logout}
},
{
    //开启持久化
    persist: true
        }
)
